package com.yocard.yxyd.ui.activity;

import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.just.agentweb.AgentWebConfig;
import com.yocard.yxyd.utils.util.ActivityUtils;
import com.gyf.barlibrary.ImmersionBar;
import com.just.agentweb.AgentWeb;
import com.yocard.yxyd.R;
import com.yocard.yxyd.ui.activity.base.SimpleActivity;
import com.yocard.yxyd.utils.util.LogUtils;
import com.yocard.yxyd.utils.util.NetworkUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created on 2019/4/22.
 */
public class WebViewActivity extends SimpleActivity {

    @BindView(R.id.ll_container)
    LinearLayout llContainer;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    protected AgentWeb mAgentWeb;
    protected String title;
    protected String url;

    @Override
    protected int getLayout() {
        return R.layout.act_webview;
    }

    @Override
    protected void initEventAndData() {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            title = extras.getString("title");
            url = extras.getString("url");
        }
        boolean connect = NetworkUtils.isConnected();
        if(connect) {
            AgentWebConfig.clearDiskCache(this);
        }
        initTitle();
        mAgentWeb = AgentWeb.with(this)
                .setAgentWebParent((LinearLayout) llContainer, new LinearLayout.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .createAgentWeb()
                .ready()
                .go(url);
    }

    private void initTitle() {
        ImmersionBar.with(this).statusBarColor(R.color.white)
                .statusBarDarkFont(true).navigationBarColor(R.color.white).init();
        tvTitle.setText(title);
    }

    @Override
    protected void onPause() {
        mAgentWeb.getWebLifeCycle().onPause();
        super.onPause();
    }

    @Override
    protected void onResume() {
        mAgentWeb.getWebLifeCycle().onResume();
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        mAgentWeb.getWebLifeCycle().onDestroy();
        super.onDestroy();
    }

    @OnClick({R.id.iv_back})
    public void onClick() {
        ActivityUtils.finishActivity(this);
    }
}
